<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>密码修改</title>
<link rel="stylesheet" type="text/css" href="../../css/Top.css" />
<link rel="stylesheet" type="text/css" href="../../css/style.css" />
<link rel="stylesheet" type="text/css" href="../../easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="../../easyui/themes/icon.css" />
<script type="text/javascript" src="../../easyui/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../js/util/jquery.cookie.js"></script>
<script type="text/javascript" src="../../js/YMLib.js"></script>
<script type="text/javascript" src="../../js/base64.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/SM4.js"></script>
</head>
<body style="margin: 10px; overflow-x: hidden; overflow-y: hidden">
<script type="text/javascript">
$(function(){
	$("#username").val($.cookie("truename"));
	$("#password1").val('1111111111');
    $("#register_btn_Save").click(function(){
    	register();
    });
});
function register(){
	/*if ($("#password1").val() == '8Mpyl+iW5bipvXJoNWhL3A==') {
		alert("不能与原密码一致，请重新填写！");
		return false;
	}*/
	if(""==$("#username").val()||""==$("#password1").val()){//用户名和原密码
		alert("用户名或密码为空");
		return false;
	}else if(""==$("#password2").val()||""==$("#password").val()){//新密码
		alert("修改的密码为空");
		$("#password").val("");
		return false;
	}else if($("#password2").val()!=$("#password").val()){//新密码
		alert("两次修改的密码输入不一致");
		$("#password").val("");
		return false;
	}else{
		suc_user();
		// checkuser();
	}
}
function randomNum(minNum, maxNum) {
	  switch (arguments.length) {
	    case 1:
	      return parseInt(Math.random() * minNum + 1, 10);
	      break;
	    case 2:
	      return parseInt(Math.random() * ( maxNum - minNum + 1 ) + minNum, 10);
	      //或者 Math.floor(Math.random()*( maxNum - minNum + 1 ) + minNum );
	      break;
	    default:
	      return 0;
	      break;
	  }
	} 
//核对原用户名密码
function checkuser(){
	var username=$("#username").val();
	var password=$("#password1").val();//原密码
	var length=password.length;
	if(length==10){length="A";}
	else if(length==11){length="B";}
	else if(length==12){length="C";}
	else if(length==13){length="D";}
	else if(length==14){length="E";}
	else if(length==15){length="F";}
	else if(length==16){length="G";}
	password =length+password+randomNum(10000000,99999999);
	var base64 = new Base64();
	password =base64.encode(password);
	$.ajax({
		 type : "POST",
		 url : "../../xtgl/login.do",
		 dataType : 'json',
		 data : {
				'master.truename' : username,
				'master.password' : password,
				'master.code':'AAAA'
			},
		 success : function(msg){
			 if(msg) suc_user();
			 else alert("用户名或原始密码错误！");
		 },
		 error : function(){
			 YMLib.Tools.Show('用户名或原始密码错误！',3000);
		 }
	});
}

function  SM4Encode(str) {
	return SM4.encode({input:str,key:'abcdefzhanxyygf'});
}

// 较验密码的合法性
function findPasswordValidate(str){
	var reg = new RegExp(/^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&amp;*])[\da-zA-Z\\.~!@#$%^&amp;*]{8,}$/);

	if (reg.test(str)) {
		console.log('胜利通过验证！');
		return true;
	}
	console.log('没有通过验证！');
	return false;
}

function suc_user(){
	var username = $("#username").val();
	var password = $("#password2").val();
	if (!findPasswordValidate(password)) {
		alert('密码长度为8位以上，且包括【数字、字母、特殊字符】！');
		return;
	}
	var sm4Password = SM4Encode(password);
	$.ajax({
		 type : "POST",
		 url : "../../xtgl/updatePassword.do",
		 dataType : 'json',
		 data: "username="+username+"&password="+encodeURIComponent(sm4Password),
		 /*data : {
				'username' : username,
				'password' : encodeURIComponent(sm4Password)
			},*/
		 success : function(msg){
			 alert('修改密码成功！');
			 // window.location.href = "../../login.jsp";
			 parent.location.href = "../../login.jsp";
			// parent.$("#updatePassword").window('destroy');
		 },
		 error : function(){
			 YMLib.Tools.Show('服务器请求失败！',3000);
		 }
	});
}
</script>
<object classid="clsid:B6BE32E6-5B1B-4A44-BA6C-FB24016CF9A7" id="IAWebClient" name="IAWebClient" style="left: 0px; top: 0px" widtd="0" height="0"></object>
<div>
	<form>
		<table  cellspacing="0" class="table_grid">
			<tr>
				<td align="right" >用户名：</td>
				<td align="left"  >
					<input widtd="200px" type="text" id="username" name="username" readonly="readonly">
					<div><span id="test0" style="color: Red;"></span> </div>
				</td>
			</tr>
			<tr>
				<td align="right" >原密码：</td>
				<td align="left"  >
					<input type="password" id="password1" disabled >
					<div><span id="test0" style="color: Red;"></span> </div>
				</td>
			</tr>
			<tr>
				<td align="right" >新密码：</td>
				<td align="left"  >
					<input type="password" id="password2">
					<div><span id="test0" style="color: Red;"></span> </div>
				</td>
			</tr>
			<tr>
				<td align="right" >重复新密码：</td>
				<td align="left" >
					<input type="password" id="password" name="password">
					<div><span id="test0" style="color: Red;"></span> </div>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<span style="color: red;font-size: 12px;font-family: '宋体'">温馨提示：新密码由八位以上且包含【字母、数字、特殊字符】组成.</span>
				</td>
			</tr>
		</table>
	</form>
</div>
<div style="text-align: center;">	
	<a id="register_btn_Save" iconCls="icon-save" href="javascript:void(0)"  class="easyui-linkbutton" style="margin:2px 3px 0px 0px;" plain="true" >保　存</a>
</div>
</body>
</html>